package fr.upmc.aladyn.transactionables.saveobject;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import fr.upmc.aladyn.transactionables.saveobject.SaveRestoreObject;
import fr.upmc.aladyn.transactionables.tests.objects.Point;


/**
 * <p>Test class</p>
 * @author Alexis Deluze
 *
 */
public class TestManuelSimple {
	private Point point;
	private SaveRestoreObject sro;
	private int xini;
	private int yini;
	
	@Before
	public void initialise(){
		System.out.println("Debut du Test TestSimple");
		
		point = new Point(0, 0);
		
		xini = (int) point.getX();
		yini = (int) point.getY();
		
		sro = new SaveRestoreObject(point);
	}
	
	
	@After
	public void end(){
		System.out.println("Fin du Test TestSimple");
	}
	
	@Test
	public void test() {
		
		try {
			 
			sro.save();
			
			point.setX(2);
			
			methodWithException();
			
			point.setY(3);

		} catch (Exception e) {
			sro.restore();
		}
		
		assertTrue(xini == point.getX());
		assertTrue(yini == point.getY());
		
	}
	
	public void methodWithException() throws Exception{
		System.out.println("Lancement d'une exception.");
		throw new Exception("Lancement d'une exception.");
	}
}
